﻿using System.Runtime.Serialization;

namespace TDMS.Net;

[Serializable]
public class TdmsException : SystemException
{
    public TdmsException()
    {
    }


    public TdmsException(string message) : this(message, null)
    {
    }

    public TdmsException(string message, Exception? inner) : this(message, inner, 0)
    {
    }
    
    public TdmsException(string message, int errorCode) : this(message, null, errorCode)
    {
    }
    
    public TdmsException(string message, Exception? inner, int errorCode) : base(message, inner)
    {
        this._errorCode = errorCode;
    }

    protected TdmsException(SerializationInfo info, StreamingContext context) : base(info, context)
    {
        if (info == null)
        {
            throw new ArgumentNullException(nameof(info));
        }
        this._errorCode = info.GetInt32("ErrorCode");
    }

    public override void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        base.GetObjectData(info, context);
        if (info == null)
        {
            throw new ArgumentNullException(nameof(info));
        }
        info.AddValue("ErrorCode", this._errorCode);
    }

    /// <summary>
    /// Gets the error code associated with the error.
    /// </summary>
    /// <value>
    /// The value of the error code.
    /// </value>
    public int ErrorCode => this._errorCode;

    // Token: 0x040000A4 RID: 164
    private const string ErrorCodeKey = "ErrorCode";

    // Token: 0x040000A5 RID: 165
    private readonly int _errorCode;
}